Delete similar requirement

Hello 
I have this dxl, an horrible dxl, but the idea is that after I some selected requirements, these are copied to the module I wish, and if there are requirements with the same "Req tag",  the oldest one would be deleted. 
 
The problem is that the way the dxl is now, despite the print show me the right amount of requirements to be deleted, one requirement always remains after I run the dxl. 
Another problem is that due to the way the delete conditions are made, the requirements cannot be created on the same date or  both will be deleted, although procedurally it is not allowed, the simple fact of being a possibility is already a problem. 
I thought about creating an attribute. ie "Copied" that would serve as a condition to the filter, but I stuck with this dxl progress, do you have any suggestions?

braolive - Wed Apr 30 17:31:15 EDT 2014

Re: Delete similar requirement
llandale - Thu May 01 12:43:05 EDT 2014

I did not follow the entire thing.  However:

Function killduplicated():

  • Function killduplicated() takes parameter "targetMod", yet you do not use it.  Your code therefore makes the common but critical error of confusing the module you are working on with the "current" module.  I think the "current" module is actually the "sourceMod" when this function gets called, and therefore it messes up your filters.  I think you can fix killduplicated() as follows:
    • Replace references to "m" with "targetMod"
    • Replace line 3 "module m = current" with "current = targetMod".
  • I think variable "objID" should be a string.  Also "modOn".
  •  turn filtering off before the 1st loop.
  • showDeletedObject(m) before purging starts

Function killduplicated() is purging (hardDelete) objects inside the loop inside a filter.  This messes up the loop and the filter.  You should identify which objects you want to purge, then purge them:

  • Skip skpPurges = create
  • for o in mod do
  • {  if(I want to purge this object) then put(skpPurges, o, o)
  • }
  • for o in skpPurges do
  • {  PurgeThisObject(o)
  • }

The purge algorithm needs to be recursive; first purging the childless descendants.  Change "hardDelete(oc)" with "DeleteObject(oc)".

I dislike using Filters to find objects in DXL.  It causes problems especially when you are mucking with the results of the Filter, such as purging objects.  It CAN work and maybe it does; but it sure doesn't feel right.

-Louie